package educrypt.database;

import java.sql.*;

public class Connector {

	private static Connection connection;

	// ~/.educrypt/db/educryptdb
	private static final String DATABASE_PATH = System.getProperty("user.home")
			+ "/.educrypt/db/educryptdb";
	private static final String DATABASE_USER = "sa";
	private static final String DATABASE_PASS = "";

	public static Connection getConnection() throws SQLException {
		if (connection == null || connection.isClosed()) {
			try {
				Class.forName("org.h2.Driver");
				connection = DriverManager.getConnection("jdbc:h2:"
						+ DATABASE_PATH, DATABASE_USER, DATABASE_PASS);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		return connection;
	}

	public static void releaseConnection() {
		if (connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
